package com.codyy.lib.base.application.repos.viewmodel

import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.liveData
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.DividerItemDecoration.HORIZONTAL
import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL
import com.codyy.lib.base.application.AppContext
import com.codyy.lib.base.application.repos.adapter.DataBindingAdapter
import com.codyy.lib.base.application.repos.model.Batch
import com.codyy.lib.base.application.repos.repository.ReposRepository
import com.codyy.lib_common.base.viewmodel.BaseViewModel
import com.codyy.lib_common.ext.yes
import com.kennyc.view.MultiStateView

class ReposViewModel(private val mReposRepository: ReposRepository) : BaseViewModel() {
    val adapter = DataBindingAdapter()
    val mDividerItemDecoration = DividerItemDecoration(AppContext, VERTICAL)
    fun getOrderList(): LiveData<Batch> = emit {
        mReposRepository.getOrderList()
    }

    fun getOrderListWithLaunch() {
        launch {
            adapter.data = mReposRepository.getOrderList().data.toMutableList()
        }
    }

    fun getOrderListWithLaunchAndError() {
        launch(
            {
                adapter.data = mReposRepository.getOrderList().data.toMutableList()
            }, {
               //自定义异常处理
            }
        )
    }

}